package org.yankun.exam4j.core.answer.service.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.yankun.exam4j.common.daobase.DaoBase;
import org.yankun.exam4j.core.answer.service.AnswerService;
import org.yankun.exam4j.entity.Answer;

@Transactional
@Service
public class AnswerServiceImpl implements AnswerService {
	
	@Resource
	private DaoBase<Answer> dao;
	
	
	@Override
	public Answer getAnswerByAnswerId(Serializable answerId) {
		
		return dao.getHibernateTemplate().get(Answer.class, answerId);
	}

	
	@Override
	public List<Answer> getAnswersByResultIdAndQuestionId(
			Serializable resultId, Serializable questionId) {
		
		String hql = "from Answer where result.uid = ? and question.uid = ? order by uid";
		
		return dao.hql(hql, new Object[]{resultId,questionId});
	}


	@Override
	public void update(Answer answer) {
		dao.update(answer);
		
	}


	@Override
	public void delete(Answer answer) {
		dao.delete(answer);
	}


	@Override
	public void save(Answer answer) {
		dao.save(answer);
	}


	@Override
	public void deleteAnswerByResultIdAndQuestionId(Serializable resultId,
			Serializable questionId) {
		String hql = "delete from Answer where result.uid = ? and question.uid = ? order by uid";
		dao.getHibernateTemplate().bulkUpdate(hql, new Object[]{resultId,questionId});
		
	}





}
